package com.ruoyi.project.sell.customer.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.sell.customer.domain.SellCustomer;
import com.ruoyi.project.sell.customer.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public List<SellCustomer> selectCustomerService(SellCustomer sellCustomer) {
        return customerMapper.selectCustomerMapper(sellCustomer);
    }

    @Override
    public String checkCusNameUnique(SellCustomer sellCustomer) {
        Long cusId = StringUtils.isNull(sellCustomer.getCusId()) ? -1L : sellCustomer.getCusId();
        SellCustomer info = customerMapper.checkCusNameUnique(sellCustomer.getCusName());
        if (StringUtils.isNotNull(info) && info.getCusId().longValue() != cusId.longValue())
        {
            return UserConstants.Customer_NAME_NOT_UNIQUE;
        }
        return UserConstants.Customer_NAME_UNIQUE;
    }
    //新增客户信息
    @Override
    public int insertSellCustomer(SellCustomer sellCustomer) {
        return customerMapper.insertCustomerMapper(sellCustomer);
    }

    @Override
    public int deleteSellCustomerByIds(String ids) {
        Long[] cusids = Convert.toLongArray(ids);
        return customerMapper.deleteCustomerMapper(cusids);
    }

    @Override
    public SellCustomer selectCustomerById(Integer cusId) {
        return customerMapper.selectCustomerByIdMapper(cusId);
    }

    @Override
    public int updateCustomerService(SellCustomer sellCustomer) {
        return customerMapper.updateCustomerMapper(sellCustomer);
    }
}
